package model;

import connection.DbConnection;
import bean.Poll;
import bean.Question;

import java.sql.*;

public class CreateMQuestionImpl {
	
	
	/**
	 * Sets all PollUser javabean attributes from database (even if empty in database).
	 * 
	 * @param user is PollUser bean
	 */

		
			private static PreparedStatement st;
			private static Connection conn;
			private static ResultSet rs;
				
			public void createquestion(Question question){
				
				
				try{
					rs = null;
					conn = new DbConnection().getConn();
					
					System.out.println(question.getText());
					st = conn.prepareStatement("insert into Question (text, status, type, font, fontsize, color, chartstyles, timer, rescounter, cai) values (?,?,?,?,?,?,?,?,?,?)");
					
					st.setString(1, question.getText());
					st.setInt(2, question.getStatus());
					st.setString(3, question.getType());
					st.setString(4, question.getFont());
					st.setInt(5, question.getFontSize());
					st.setString(6, question.getColor());
					st.setString(7, question.getCharStyles());
					st.setInt(8, question.getTimer());
					st.setString(9, question.getResCounter());
					st.setString(10, question.getCAI());
					rs=st.executeQuery();	
					 
			    	
			    	
					
				}catch(Exception e){
					e.printStackTrace();
				}
			}
				public void insertpq(Poll poll){
					
					
					try{
						rs = null;
						conn = new DbConnection().getConn();
						
						
						st = conn.prepareStatement("insert into Poll_Question values (?,?,(select max(questionid) from question),?)");	
						st.setInt(1, poll.getId());
						st.setInt(2, poll.getVersion());
						st.setString(3, poll.getName());
						rs=st.executeQuery();	
						 
				    	
				    	
						
					}catch(Exception e){
						e.printStackTrace();
					}
			}
}